package com.feihong.txgw.adapter.nearbystore;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.adapter.base.BaseQuickAdapter;
import com.adapter.base.BaseViewHolder;
import com.adapter.base.animation.ScaleInAnimation;
import com.feihong.txgw.R;
import com.feihong.txgw.model.bean.nearby.NearbyModel;
import com.feihong.txgw.utils.adress.StringEmpty;

import java.util.List;

/**
 * @Author wangziheng
 * @ProjectName txgw_app
 * @ClassName NearByStoresReAdapter
 * @package com.feihong.txgw.adapter.nearbystore
 * @data 2018/6/7 13:29
 * @Describe
 * @Change
 */
public class NearByStoresReAdapter extends BaseQuickAdapter<NearbyModel.DataBean.ListBean,BaseViewHolder> {

    private ImageView iv_p,iv_car,iv_tel;
    private TextView tv_yindao;
    private int mTagLength = 5;
    private TextView[] tvs = new TextView[mTagLength];
    public NearByStoresReAdapter(int layoutResId) {
        super(R.layout.item_fujinmendian_lv);
        openLoadAnimation(new ScaleInAnimation(0.8f));
        isFirstOnly(false);
    }

    @Override
    protected void convert(BaseViewHolder helper, NearbyModel.DataBean.ListBean item) {
        if (!TextUtils.isEmpty(item.getStore_name())) {
            helper.setText(R.id.store_id,item.getStore_name());
        } else {
            helper.setText(R.id.store_id,"          ");
        }
        helper.setText(R.id.tv_distance,item.getDistance() + "km");
        if (!TextUtils.isEmpty(item.getStore_addr())) {
            helper.setText(R.id.store_name,item.getStore_addr());
        }
        tvs[0] = helper.getView(R.id.tv_xiao);
        //转卖
        tvs[1] = helper.getView(R.id.tv_zhuan);
        //回收
        tvs[2] = helper.getView(R.id.tv_hui);
        //维修
        tvs[3] = helper.getView(R.id.tv_xiu);
        //维修
        tvs[4] = helper.getView(R.id.tv_ka);

        iv_p = helper.getView(R.id.iv_p);
        iv_car = helper.getView(R.id.iv_car);
        iv_tel = helper.getView(R.id.iv_tel);
        tv_yindao = helper.getView(R.id.tv_stopcar);
        tvs[0].setVisibility(View.GONE);
        tvs[1].setVisibility(View.GONE);
        tvs[2].setVisibility(View.GONE);
        tvs[3].setVisibility(View.GONE);
        tvs[4].setVisibility(View.GONE);
        List<String> p = item.getStore_service();
        int leng = Math.min(p.size(), mTagLength);
        if (p != null) {
            for (int i = 0; i < leng; i++) {
                if (!StringEmpty.isEmpty(p.get(i))) {
                    if (i <= mTagLength) {
                        tvs[i].setVisibility(View.VISIBLE);
                        tvs[i].setText(p.get(i));
                    }
                }
            }
        }
        int tc = item.getTc();
        int gc = item.getTc();
        int tel = item.getTc();
        int tczy = item.getTc();
        if (tc == 1 || !TextUtils.isEmpty(item.getStore_addr())) {
            iv_p.setVisibility(View.VISIBLE);
        } else {
            iv_p.setVisibility(View.GONE);
        }
        if (gc == 1 || !TextUtils.isEmpty(item.getStore_addr())) {
            iv_car.setVisibility(View.VISIBLE);
        } else {
            iv_car.setVisibility(View.GONE);
        }
        if (tel == 1) {
            iv_tel.setVisibility(View.VISIBLE);
        } else {
            iv_tel.setVisibility(View.GONE);
        }
        if (tczy == 1) {
            tv_yindao.setVisibility(View.VISIBLE);
        } else {
            tv_yindao.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(item.getOpening_time())) {
            helper.setText(R.id.tv_worktime,"工作时间:" + item.getOpening_time());
        }
        helper.addOnClickListener(R.id.iv_tel);
    }
}
